#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int findLHS(vector<int>& nums) {
        unordered_map<int, int> hash;
        for (auto& e : nums) hash[e]++;
        int res = 0;
        for (auto& [k, v] : hash)
        {
            if (hash.find(k + 1) != hash.end())
                res = max(res, v + hash[k + 1]);
        }
        return res;
    }
};